<template>
  <div class="addFeed" :style="'height:' + height + 'px;'">
    <div>
      <HeadTop :title="headTitle"></HeadTop>
      <div class="head-time">{{new Date | format}}</div>
    </div>
    <div class="addClass">
      <div class="addClass-title">生物</div>
      <div class="addClass-line"></div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物名称</div>
        <div class="addFeed-con-msg">
          <van-dropdown-menu>
            <van-dropdown-item v-model="value" :options="opt" />
          </van-dropdown-menu>
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物计量单位</div>
        <div>
          <input class="addFeed-con-msg" :value="opt[value].measurement" disabled/>
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">生物数量</div>
        <div>
          <input class="addFeed-con-msg" v-model="biologyQuantity"/>
        </div>
      </div>
      <div class="addFeed-con">
        <div class="addFeed-con-name">操作</div>
        <div class="addFeed-con-msg">
          <van-dropdown-menu>
            <van-dropdown-item v-model="value2" :options="opt2" />
          </van-dropdown-menu>
        </div>
      </div>
    </div>
    <div class="addClass">
      <div class="addClass-title">备注</div>
       <textarea  rows="2" class="addClass-title-text" v-model="tips"></textarea>
    </div>
    <div class="addClass-btn">
      <div class="addClass-btn-hold" @click="submit(0)">保存</div>
      <div class="addClass-btn-submit" @click="submit(1)">提交</div>
    </div>

  </div>
</template>
<script>
import { getBiologyListByFishTankId, getBiologyOperation, addBiologyReport } from '../../../api/index.js'
import HeadTop from '../../../components/headTop.vue'
import { getYYYYMMDD } from '../../../api/unit.js'
export default {
  data () {
    return {
      headTitle: '1号鱼缸数量报表',
      value: 0,
      opt: [],
      value2: 0,
      opt2: [],
      height: document.documentElement.clientHeight,
      tips: '',
      biologyQuantity: ''
    }
  },
  filters: {
    format: function (value) {
      return getYYYYMMDD(value).nTime
    }
  },
  async mounted () {
    let msg = await getBiologyListByFishTankId('a8e986eb-2d28-40cb-bdec-699c199d1e4c')
    let idx = 0
    msg.data.map(v => {
      v.text = v.biologyName
      v.value = idx
      idx++
    })
    this.opt = msg.data
    this.value = msg.data[0].value
    let msg2 = await getBiologyOperation('a8e986eb-2d28-40cb-bdec-699c199d1e4c')
    idx = 0
    msg2.data.map(v => {
      v.text = v.operationName
      v.value = idx
      idx++
    })
    this.opt2 = msg2.data
    this.value2 = msg2.data[0].value
  },
  methods: {
    async submit (v) {
      if (this.biologyQuantity === '') {
        this.$notify({ type: 'danger', message: '请输入数量' });
        return
      }
      let data = {
        fishTankId: 'a8e986eb-2d28-40cb-bdec-699c199d1e4c',
        biologyId: this.opt[this.value].id,
        biologyQuantity: this.biologyQuantity,
        operationId: this.opt2[this.value2].id,
        remark: this.tips,
        submit: v
      }
      await addBiologyReport(data)
      this.$router.go(-1)
    }
  },
  components: {
    HeadTop
  }
}
</script>

<style scoped>
.addFeed{
  background: #e5e5e5;
}
.head-time{
  width:750px;
  height:109px;
  background: #fff;
  border-top: #e5e5e5 2px solid;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size:32px;
  font-weight: bold;
}
.addClass{
  background: #fff;
  width: 686px;
  border-top: #e5e5e5 solid 17px;
  padding: 40px 32px;
  font-size: 32px;
  overflow: hidden;
}
.addClass-title{
  padding-bottom: 40px;
  font-weight: bold;
  margin-left: 5px;
}
.addClass-line{
  background-color: #e5e5e5;
  height: 1px;
  width: 686px;
}
.addFeed-con{
  display: flex;
  font-size: 28px;
  color: #757575;
  height: 45px;
  line-height: 45px;
  margin-top: 34px;
}
.van-dropdown-menu{
  height: 45px;
  background: #f9f9f8;
  text-align: left;

}
.addFeed-con-name{
  width: 200px;
  margin-left: 12px;
}
.addFeed-con-msg{
  padding: 0 25px;
  width: 433px;
  background: #f9f9f8;
}
.addClass-title-text{
  width: 675px;
  background: #FBF8F9;
  line-height: 54px;
  border: 1px solid #e5e5e5;
}
.addClass-btn{
  width: 750px;
  background: #e5e5e5;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 154px;
  font-size: 32px;
}
.addClass-btn-hold{
  width: 332px;
  height: 111px;
  line-height: 111px;
  text-align: center;
  background: #fff;
  font-weight: bold;
  color: #999;
}
.addClass-btn-submit{
  width: 332px;
  height: 111px;
  line-height: 111px;
  text-align: center;
  color: #009EEA;
  background: #fff;
  font-weight: bold;
}
</style>
